(async function(){
    //逻辑太简单了，看提示就知道做了什么，就不一一注解了
    if (!checkConnect()) return;
    var rtn = await loadManbers();
    if (rtn){
        var my = getMy();
        if (!my || !my.isReal){
            alert("您还不是正式会员");
            return;
        }
        setList("proposers");
        getNode("addProposal").onclick=async function(){
            if (!checkConnect()) return;
            var name = getNode("name").value;
            var byToken = getNode("byToken").checked;
            var isBig = getNode("isBig").checked;
            var isAnonymous = getNode("isAnonymous").checked;
            var proposers = getList("proposers");
            var proposal = getNode("proposal").value;
            var win = getNode("win").value;
            var ratio = parseInt(getNode("ratio").value*100);
            if (name.length==0) {
                alert("提案名不能为空");
                return;
            }
            if (proposal.length==0) {
                alert("提案内容不能为空");
                return;
            }
            if (proposers.length==0) {
                alert("提案人不能为空");
                return;
            }
            if (ratio<=0 || win>10000) {
                alert("最低投票人数比例");
                return;
            }
            if (win<=0 || win>100) {
                alert("表决通过比例不正确");
                return;
            }
            if (proposers.length==0) {
                alert("提案者地址不不可为空");
                return;
            }
            for(var i=0;i<proposers.length;i++){
                if (proposers[i].length!=42 || proposers[i].substr(0,2)!="0x") {
                    alert("提案者地址不正确");
                    return;
                }
            }
            setLoading(1);
            const rtn = await createProposal("发起新提案",name,proposal,isBig,isAnonymous,byToken,win,proposers,ratio);
            if (rtn){
                var param={webapi:"insertProposal","id":rtn.toNumber(),"proposal":proposal};
                callAPI(param);
                publicParam.proposals = null;
                setLoading(0);
                goto("proposal/list");
            }
            setLoading(0);
        };
    }
})();